<?php 
if ($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['user_id'])) {
	require_once 'db.inc.php';
	$result = mysql_query("SELECT * FROM users ".TABLE_PREFIX."WHERE id = " . $_GET['user_id']) or die(mysql_error());
	echo json_encode(array(
			"contract" => mysql_result($result, 0, 'contract'),
			"loan" => mysql_result($result, 0, 'loan'),
			"push" => mysql_result($result, 0,'push')
	));
} else if ($_SERVER['REQUEST_METHOD'] === 'POST') {
	require_once 'db.inc.php';
} else {
	header("HTTP/1.1 400 Bad Request");
}

/*if ($_SERVER['REQUEST_METHOD'] !== 'POST'
		|| !(isset($_POST['user_id']) && isset($_POST['origin']) 
			&& isset($_POST['contract']) && isset($_POST['loan']) 
			&& isset($_POST['push']))) {
	header("HTTP/1.1 400 Bad Request");
	exit;
}

require_once 'db.inc.php';

mysql_query(sprintf("UPDATE users SET contract = ?, loan = ?, push = ?",
		$_POST['contract'], $_POST['loan'], $_POST['push'])) or die(mysql_error());
require_once 'gcm.send.php';
sendPreferences($_POST['user_id'], $_POST['origin']);
header("HTTP/1.1 201 Updated");
*/
?>